<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div class="box">
    Lorem, ipsum dolor sit amet consectetur adipisicing elit. Natus dolore delectus numquam autem eos. Iusto ipsa
    neque nobis dicta ducimus beatae vitae, corporis voluptas, cupiditate at culpa recusandae dolore voluptate!
  </div>

  <script>
    // 测试发现的bug：Chrome 下无问题；firefox 下必须要先打开一下开发者工具，然后才会生效
    window.addEventListener('beforeunload', ev => {
      ev.preventDefault();
      ev.returnValue = '确定要离开吗？'
    });

    const a = "dg";
    const b = 'dd'
  </script>
</body>

</html>